//
//  TextCell.m
//  WOPrototype
//
//  Created by Olof Millberg on 2010-04-27.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "TextCell.h"

@implementation TextCell

@synthesize textLabel;
@synthesize editButton;
@synthesize text;
@synthesize placeHolder;
@synthesize title; 
@synthesize viewController; 
@synthesize delegate;
@synthesize editable;

- (void) setEditable:(BOOL)isEditable
{
	editable = isEditable;
	if (editable)
	{
		// TODO: Make it look "editable"
	}
}

- (void) setText:(NSString *)aText
{
	[text release];
	text = [aText retain];
	
	if ([aText isEqualToString:@""])
	{
		textLabel.text = placeHolder;
		textLabel.textColor = [UIColor lightGrayColor];
	}
	else
	{
		textLabel.text = aText;
		textLabel.textColor = [UIColor blackColor];
	}
	textLabel.frame = CGRectMake(10, 6, 280, [textLabel.text sizeWithFont:[UIFont systemFontOfSize:15.0f]
							  constrainedToSize:CGSizeMake(280.f, 120.f)
								  lineBreakMode:UILineBreakModeWordWrap].height);
	editButton.frame = CGRectMake(0, 0, textLabel.frame.size.width + 12, textLabel.frame.size.height + 20);
}

- (IBAction) showNoteView
{
	if(!editable || !viewController)
		return;
	
	[self setSelected:NO animated:YES];
	
	WONewNoteViewController *noteVC = [[WONewNoteViewController alloc] init];
	noteVC.text = self.text;
	noteVC.delegate = self.delegate;
	noteVC.title = self.title;
	[viewController.navigationController pushViewController:noteVC animated:YES];
	[noteVC release];
}

- (void) dealloc
{
	[textLabel release];
	[text release];
	[placeHolder release];
	[title release];
	[viewController release];
	[super dealloc];
}

- (void) select
{
	if (editable)
		[self setSelected:YES animated:NO];
}

- (void) deselect
{
	if (editable)
		[self setSelected:NO animated:YES];
}

@end
